package com.ydcycloud.job.controller.common;


import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.smart.mvc.model.Pagination;
import com.ydcycloud.base.bean.CommonResult;
import com.ydcycloud.base.enums.CommonEnums;
 import com.ydcycloud.job.service.JobService;
import com.ydcycloud.sys.controller.BaseWapController;
import com.ydcycloud.sys.util.CommonUtil;

@Controller
@RequestMapping("/common/job")
public class JobCommonController extends BaseWapController {

	@Resource
	private JobService jobService;
	
	@RequestMapping("/findJob")
	public @ResponseBody
	CommonResult findJob(HttpServletRequest request, Integer pageNo, Integer pageSize, Integer areaCode, String jobName,String profession,String sortType,Integer companyId) {
		CommonResult r = new CommonResult();

		try {  
			if(pageNo == null || pageSize == null || pageNo < 1){
				commonEnums = CommonEnums.PARANETER_ERROR;//302 参数错误
			}else{
				Pagination<Map<String,Object>> p = jobService.findJob(pageNo, pageSize, areaCode, jobName, profession, sortType, companyId);
	
				if(p != null){
					r.setData(CommonUtil.PaginationToMap(p, "list"));
				}
				commonEnums = CommonEnums.SUCCESS;//300 成功
			}
		} catch (Exception e) {
			e.printStackTrace();
			commonEnums = CommonEnums.SYSTEM_ERROR; // 301 系统错误
		} finally {
			r.setStatus(commonEnums.getValue());
			r.setMessage(commonEnums.getLabel());
		}

		return r;
	}
	
	@RequestMapping("/getDetail")
	public @ResponseBody
	CommonResult getDetail(HttpServletRequest request, Integer jobId){
		CommonResult r = new CommonResult();
		try{	
				if(jobId == null || jobId < 1){
					commonEnums = CommonEnums.PARANETER_ERROR;// 302 参数错误
				}
			Map<String,Object>infoDetail= jobService.getDetail(jobId);
				if(infoDetail == null){
					r.setData("");
				}else{
					r.setData(infoDetail);
				}
				commonEnums = CommonEnums.SUCCESS;//300 成功
		}catch(Exception e){
			commonEnums = CommonEnums.SYSTEM_ERROR;// 301 系统错误
			e.printStackTrace();
		}finally{
			r.setMessage(commonEnums.getLabel());
			r.setStatus(commonEnums.getValue());
		}
		return r;
	}
	
}
